-- poisoned
-- created by panyl
-- 中毒

return {
    apply = function(prop, baseValue)
        return baseValue + prop[3];
    end,

    -- 每回合触发
    trigger = function(who, prop, arg)
        -- 需要和楼层、难度系数挂钩
        local floor = DungeonM.currentLayer();
        local dungeonId = DungeonM.getDungeonId();
        if dungeonId == nil then
            dungeonId = ME.user.dbase:query("currentDungeon");
        end
        local layerFix = DungeonAreaM.query(dungeonId,"layer_fix");

        local value = math.modf(floor * (60 + layerFix) * prop[3] / 60 / 1000);

        -- 降低中毒燃烧伤害
        local p = PropM.combine(who, "poisoned_resist", 1);
        value = PropM.apply(p, value);

        -- 毒抗
        p = PropM.combine(who, "poisoned_resist2", 1);
        value = PropM.apply(p, value);

        -- 最小一点
        value = math.max(1, value);

        -- 专属免疫
        local arr = PropM.combine(who, "immunity2", PropM.getPropId("poisoned"));
        if PropM.apply(arr, value) > 0 then
            return 0;
        end

        return CombatM.receiveDamage(who, who, value, 0);
    end,

    desc = function(prop)
        local row = PropM.getRow(prop[1]);
        local desc = row.desc;

        local floor = DungeonM.currentLayer();
        local dungeonId = DungeonM.getDungeonId();
        if dungeonId == nil then
            dungeonId = ME.user.dbase:query("currentDungeon");
        end
        local layerFix = DungeonAreaM.query(dungeonId,"layer_fix");

        local value = math.modf(floor * (60 + layerFix) * prop[3] / 60 / 1000);

        -- 最小一点
        value = math.max(1, value);

        -- 专属免疫
        local arr = PropM.combine(ME.user, "immunity2", PropM.getPropId("poisoned"));
        if PropM.apply(arr, value) > 0 then
            value = 0;
        end

        return string.gsub(desc, "{1}", value);
    end,

    record = function(target, prop, path)
        return false;
    end
};